#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Filename: capture_add_dir.py
# Author: ChenChangSong
# Date: 2025-08-24

"""
功能描述: 新增子目录
"""
from comm.common_code import *

def capture_add_dir(parent_id, dir_name):
    """
    新增子目录
    :return:
    """
    excel_data = get_excel_data()
    url = f"https://www.tapd.cn/{excel_data['项目ID']}/sparrow/tcase_categories/quick_add_category"
    payload = f"data%5BTcaseCategory%5D%5Bid%5D=&data%5BTcaseCategory%5D%5Bparent_id%5D={parent_id}&data%5BTcaseCategory%5D%5Bname%5D={dir_name}&data%5BTcaseCategory%5D%5Bdescription%5D="
    headers = {
    'Accept': '*/*',
    'Accept-Language': 'zh-CN,zh;q=0.9',
    'Connection': 'keep-alive',
    'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
    'Cookie': excel_data['Cookie'],    
    'DSC-TOKEN': 'mN0JGhSb2wo5jGIq',
    'Origin': 'https://www.tapd.cn',
    'Referer': f'https://www.tapd.cn/{excel_data["项目ID"]}/sparrow/tcase/tcase_list?data[Filter][name]=&async=1&category_id={parent_id}&select_workspace={excel_data["项目ID"]}',
    'Sec-Fetch-Dest': 'empty',
    'Sec-Fetch-Mode': 'cors',
    'Sec-Fetch-Site': 'same-origin',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.5845.97 Safari/537.36 Core/1.116.554.400 QQBrowser/19.5.6663.400',
    'X-Requested-With': 'XMLHttpRequest',
    'sec-ch-ua': '"Not)A;Brand";v="24", "Chromium";v="116"',
    'sec-ch-ua-mobile': '?0',
    'sec-ch-ua-platform': '"Windows"'
    }
    response_code, response = api_request(method="POST", url=url, headers=headers, data=payload)
    logger.info(f"响应内容: {response}")
    logger.info(f'↑↑↑=================================================↑↑↑')

if __name__ == "__main__":
    capture_add_dir(parent_id='1148433040001001298', dir_name="测试目录22")